%matplotlib inline
import os
import xarray as xr
import numpy as np
from datetime import datetime
from os.path import isfile, basename, abspath
from pathlib import Path
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib.animation import FuncAnimation, PillowWriter
from IPython.display import display, Image, HTML
import hvplot
import hvplot.xarray
import holoviews as hv
from holoviews import opts
import earthaccess
from earthaccess import Auth, DataCollections, DataGranules, Store
hv.extension('bokeh')Working with SWOT Level 2 Water Mask Raster Image Data Product:
Working with SWOT Level 2 Water Mask Raster Image Data Product:
Local Machine Download Version
Summary & Learning Objectives
Notebook showcasing how to work with SWOT Raster Image data product version 2.0 on a local machine
- Utilizing the earthaccess Python package. For more information visit: https://nsidc.github.io/earthaccess/
- Option to query the new dataset based on users choice; choosing between two resolutions either by ‘100m’ or ‘250m’.
- Visualizing the dataset by choosing one of its various variables.
- Visualizing multiple raster images on a single map.
- Stacking multiple raster images and creating a time dimension to analyze over time.
Requirements
1. Compute environment
This tutorial is written to run in the following environment: - Local compute environment e.g. laptop, server: this tutorial can be run on your local machine
2. Earthdata Login
An Earthdata Login account is required to access data, as well as discover restricted data, from the NASA Earthdata system. Thus, to access NASA data, you need Earthdata Login. Please visit https://urs.earthdata.nasa.gov to register and manage your Earthdata Login account. This account is free to create and only takes a moment to set up.
Import libraries
Authentication with earthaccess
In this notebook, we will be calling the authentication in the below cell.
auth = earthaccess.login(strategy="interactive", persist=True)Search using earthaccess for SWOT Raster products
Each dataset has it’s own unique collection concept ID. For the SWOT_L2_HR_Raster_2.0 dataset, we can find the collection ID here.
For this tutorial, we are looking at the Lake Mead Reservoir.
We used bbox finder to get the exact coordinates for our area of interest.
results = earthaccess.search_data(
short_name = 'SWOT_L2_HR_RASTER_2.0',
bounding_box=(-115.112686,35.740939,-114.224167,36.937819),
temporal =('2024-01-01 00:00:00', '2024-01-05 23:59:59'),
granule_name = '*_100m_*',
count =200
)Granules found: 2
earthaccess.download(results, "./SWOT_Raster_LakeMead") Getting 2 granules, approx download size: 0.06 GB
['SWOT_Raster_LakeMead\\SWOT_L2_HR_Raster_100m_UTM11S_N_x_x_x_008_511_109F_20240101T124328_20240101T124347_PIC0_01.nc',
'SWOT_Raster_LakeMead\\SWOT_L2_HR_Raster_100m_UTM11S_N_x_x_x_008_511_110F_20240101T124346_20240101T124407_PIC0_01.nc']
Visualizing the Dataset
Let’s now visualize an individual layer for a single file that was downloaded using Xarray to read the NetCDF image.
file_paths = ('./SWOT_Raster_LakeMead/SWOT_L2_HR_Raster_100m_UTM11S_N_x_x_x_008_511_109F_20240101T124328_20240101T124347_PIC0_01.nc')dataset = xr.open_dataset(file_paths)dataset.wse.hvplot.image(y='y', x='x').opts(width=1000, height=600, colorbar=True)